﻿using System;
using System.Web.Configuration;

namespace Salient.Web.Administration.Security
{
    public partial class setUpAuthentication : SecurityPage
    {
        public void Page_Load()
        {
            if (!IsPostBack)
            {
                System.Configuration.Configuration config = OpenWebConfiguration(ApplicationPath);
                var auth = (AuthenticationSection) config.GetSection("system.web/authentication");
                if (auth.Mode == AuthenticationMode.Windows)
                {
                    fromInternet.Checked = false;
                    fromNetwork.Checked = true;
                }
            }
        }

        public void UpdateAndReturnToPreviousPage(object sender, EventArgs e)
        {
            System.Configuration.Configuration config = OpenWebConfiguration(ApplicationPath);
            var auth = (AuthenticationSection) config.GetSection("system.web/authentication");
            auth.Mode = fromInternet.Checked ? AuthenticationMode.Forms : AuthenticationMode.Windows;
            SaveConfig(config);
            Response.Write(auth.Mode);
            ReturnToPreviousPage(sender, e);
        }
    }
}